package com.xxx.controller;

import com.xxx.entity.Product;
import com.xxx.feignclient.ProductClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @author blijojo
 * @date 2021/5/22
 */
@RestController
@Slf4j
public class CategoryController {

    @Resource
    private ProductClient productClient;

    @GetMapping("/category/test")
    public String category() {
        log.info("category服务启动");
        String product = productClient.product();
        String list = productClient.list();
        log.info("结果1: {}", product);
        log.info("结果2: {}", list);
        return "category ok! " + product;
    }

    /**
     * 测试OpenFeign传递基本数据类型参数
     */
    @GetMapping("/category/test1")
    public String test1(String name, String age) {
        log.info("category服务启动");
        String result = productClient.test1(name, age);
        return "Category.test1 ok! " + result;
    }

    /**
     * 测试OpenFeign传递基本数据类型参数 路径传参 rest风格
     */
    @GetMapping("/category/test2")
    public String test2(String name, String age) {
        log.info("category服务启动");
        String result = productClient.test2(name, age);
        return "Category.test2 ok! " + result;
    }

    /**
     * 测试传递对象类型参数 application/json方式
     */
    @GetMapping("/category/test3")
    public String test3() {
        log.info("category服务启动");
        String result = productClient.test3(new Product("张三", 19, new Date()));
        return "Category.test3 ok! " + result;
    }

    /**
     * 测试传递数组
     */
    @GetMapping("/category/test4")
    public String test4(String[] ids) {
        log.info("category服务启动");
        String result = productClient.test4(ids);
        return "Category.test4 ok! " + result;
    }

    /**
     * 测试传递集合
     */
    @GetMapping("/category/test5")
    public String test5(String[] ids) {
        log.info("category服务启动");
        String result = productClient.test5(ids);
        return "Category.test5 ok! " + result;
    }

}
